//
//  GameInfoCell.m
//  NBANews
//
//  Created by Liccon Chang on 11-1-19.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "GameInfoCell.h"
#import "SystemUtil.h"

@implementation GameInfoCell

@synthesize Hometeam;
@synthesize Visitors;
@synthesize HometeamScore;
@synthesize VisitorsScore;
@synthesize GameTime;
@synthesize State;
@synthesize HometeamImage;
@synthesize VisitorsImage;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier data:(GameInfo*) aGameInfo{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
		[self initwithGameInfo:aGameInfo];
    }
    return self;
}

- (void) initwithGameInfo:(GameInfo*) aGameInfo{
	if (aGameInfo) {
		CGRect rect = [[UIScreen mainScreen] bounds];
		int width = rect.size.height;
		int height = 80;
		Hometeam = [[UILabel alloc] initWithFrame:CGRectMake(width / 2 - 160, 0, 120, height/2)];
		Hometeam.backgroundColor = [UIColor clearColor];
		Hometeam.textAlignment = UITextAlignmentCenter;
		Hometeam.textColor = [UIColor whiteColor];
		Hometeam.text = aGameInfo.Hometeam;
		[self addSubview: Hometeam];
		
		Visitors = [[UILabel alloc] initWithFrame:CGRectMake(width / 2 + 40, 0, 120, height/2)];
		Visitors.backgroundColor = [UIColor clearColor];
		Visitors.textAlignment = UITextAlignmentCenter;
		Visitors.textColor = [UIColor whiteColor];
		Visitors.text = aGameInfo.Visitors;
		[self addSubview: Visitors];
		
		HometeamScore = [[UILabel alloc] initWithFrame:CGRectMake(width / 2 - 120, height/2 - 20, 80, height/2)];
		HometeamScore.backgroundColor = [UIColor clearColor];
		HometeamScore.textAlignment = UITextAlignmentCenter;
		HometeamScore.textColor = [UIColor yellowColor];
		HometeamScore.text = aGameInfo.HometeamScore;
		[self addSubview: HometeamScore];
		
		VisitorsScore = [[UILabel alloc] initWithFrame:CGRectMake(width / 2 + 40, height/2 - 20, 80, height/2)];
		VisitorsScore.backgroundColor = [UIColor clearColor];
		VisitorsScore.textAlignment = UITextAlignmentCenter;
		VisitorsScore.textColor = [UIColor yellowColor];
		VisitorsScore.text = aGameInfo.VisitorsScore;
		[self addSubview: VisitorsScore];
		
		
		UIImageView* StateBgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"state.png"]];
		StateBgView.frame = CGRectMake(width / 2 - 50, 15, 100, height - 30);
		[self.contentView addSubview:StateBgView];
		[StateBgView release];
		
		GameTime = [[UILabel alloc] initWithFrame:CGRectMake(width / 2 - 60, 20, 120, height/2 - 20)];
		GameTime.backgroundColor = [UIColor clearColor];
		GameTime.textAlignment = UITextAlignmentCenter;
		GameTime.textColor = [UIColor whiteColor];
		GameTime.text = aGameInfo.GameTime;
		[self addSubview: GameTime];
		
		State = [[UILabel alloc] initWithFrame:CGRectMake(width / 2 - 60, height/2, 120, height/2 - 20)];
		State.backgroundColor = [UIColor clearColor];
		State.textAlignment = UITextAlignmentCenter;
		State.textColor = [UIColor whiteColor];
		State.text = aGameInfo.State;
		[self addSubview: State];

		//image
		UIImageView* leftImgView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 0, 80, height)];
		[leftImgView setImage:[UIImage imageNamed:[SystemUtil getTeamImageName:aGameInfo.Hometeam]]];
		[self addSubview: leftImgView];
		[leftImgView release];
		
		UIImageView* rightImgView = [[UIImageView alloc] initWithFrame:CGRectMake(width - 95, 0, 80, height)];
		[rightImgView setImage:[UIImage imageNamed:[SystemUtil getTeamImageName:aGameInfo.Visitors]]];
		[self addSubview: rightImgView];
		[rightImgView release];
	}
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state.
}


- (void)dealloc {
	[Hometeam release];
	[Visitors release];
	[HometeamScore release];
	[VisitorsScore release];
	[GameTime release];
	[State release];
	[HometeamImage release];
	[VisitorsImage release];
    [super dealloc];
}


@end
